import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.home.core/core/domain/entities/card_actions/addition_to_collection_card_action.dart';

abstract class IsAdditionToCustomCollectionCardActionPermitted {
  bool call({
    required bool lexicalItemPermitted,
    required BuiltList<AdditionToCustomCollectionCardActionCollectionInfo> collectionInfos,
    required BuiltSet<String> permittedCollectionListItemIds,
  });
}

class IsAdditionToCustomCollectionCardActionPermittedImpl
    implements IsAdditionToCustomCollectionCardActionPermitted {
  const IsAdditionToCustomCollectionCardActionPermittedImpl();

  @override
  bool call({
    required bool lexicalItemPermitted,
    required BuiltList<AdditionToCustomCollectionCardActionCollectionInfo> collectionInfos,
    required BuiltSet<String> permittedCollectionListItemIds,
  }) {
    final anyCollectionPermitted = collectionInfos.any((collectionInfo) {
      return permittedCollectionListItemIds.contains(collectionInfo.customCollection.id);
    });

    return lexicalItemPermitted && (anyCollectionPermitted || collectionInfos.isEmpty);
  }
}
